import { getStore } from '@/utils/store'
import { uploadType, getAreaObj } from '@/utils/util'

const userInfo = getStore('userInfo') || {}
export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '申诉时间',
			prop: 'createTime',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '所属区',
			prop: 'orgAreaName',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '申诉人姓名',
			prop: 'createUserName',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '申诉人联系方式',
			prop: 'createPhone',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '申诉原因',
			prop: 'appealReasonLabel',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '申诉单位所在详细地址',
			prop: 'orgAddress',
			type: 'text',
			span: 12,
		},
		{
			label: '申诉说明',
			prop: 'appealDescribe',
			type: 'text',
			span: 12,
			readonly: true,
		},
		{
			label: '申诉证明材料',
			prop: 'appealMaterial',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			onlyReady: true,
		},

		{
			label: '处理结果',
			prop: 'handleStatus',
			propName: 'handleStatusLabel',
			type: 'radio',
			dicData: [
				{
					label: '通过',
					value: '1',
				},
				{
					label: '待核实',
					value: '2',
				},
				{
					label: '驳回',
					value: '3',
				},
				{
					label: '不通过',
					value: '4',
				},
			],
			rules: [{ required: true, message: '请选择处理结果' }],
			span: 24,
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '申诉证明材料',
			prop: 'appealMaterial',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			rules: [{ required: true, message: '请上传申诉证明材料' }],
		},
		{
			label: '申诉原因',
			prop: 'appealReason',
			propName: 'appealReasonLabel',
			api: 'geiDictItemList',
			type: 'remoteSelect',
			code: 'APPEAL_REASON',
			span: 12,
			rules: [{ required: true, message: '请选择申诉原因' }],
		},
		{
			label: '申诉单位所在详细地址',
			prop: 'orgAddress',
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入申诉单位所在详细地址' }],
		},
		{
			label: '申诉说明',
			prop: 'appealDescribe',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 24,
			rules: [{ required: true, message: '请输入申诉说明' }],
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{
			type: 'selection',
			label: '选择',
			reserveSelection: true,
			hide: !userInfo.authArea,
		},
		{ label: '所属区', prop: 'orgAreaName' },
		{ label: '工单编号', prop: 'orderNo' },
		{ label: '服务组织单位', prop: 'organizationName' },
		{ label: '服务对象姓名', prop: 'elderlyName' },
		{ label: '服务对象身份证号', prop: 'elderlyIdCard' },
		{ label: '服务人员', prop: 'staffName' },
		{ label: '工单开始时间', prop: 'orderStartTime' },
		{ label: '工单结束时间', prop: 'orderEndTime' },
		{ label: '服务时长', prop: 'organizationName' },
		{
			label: '异常原因',
			prop: 'errorInfo',
		},
		{
			label: '申诉处理状态',
			prop: 'handleStatus',
			custome: 'tag',
			dicData: [
				{
					label: '待处理',
					value: 0,
					type: 'warning',
				},
				{
					label: '通过',
					value: 1,
					type: 'success',
				},
				{
					label: '待核实',
					value: 2,
					type: 'primary',
				},
				{
					label: '驳回',
					value: 3,
					type: 'danger',
				},
				{
					label: '不通过',
					value: 4,
					type: 'danger',
				},
			],
		},
		{
			label: '申诉结果',
			prop: 'handleResult',
			custome: 'tag',
			dicData: [
				{
					label: '有效',
					value: 1,
					type: 'success',
				},
				{
					label: '异常',
					value: 0,
					type: 'danger',
				},
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 140,
			fixed: 'right',
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '工单编号',
			prop: 'orderNo',
			type: 'input',
			span: 8,
		},
		{
			label: '服务组织单位',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '服务对象',
			prop: 'elderlyName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'elderlyIdCard',
			type: 'input',
			span: 8,
		},
		{
			label: '服务人员',
			prop: 'staffName',
			type: 'input',
			span: 8,
		},
		{
			label: '工单时间',
			prop: 'orderServiceTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '异常原因',
			prop: 'errorInfo',
			type: 'input',
			span: 8,
		},
	],
}

export const appealFormConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '申诉证明材料',
			prop: 'appealMaterial',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			disabled: true,
		},
		{
			label: '申诉原因',
			prop: 'appealReason',
			propName: 'appealReasonLabel',
			api: 'geiDictItemList',
			type: 'remoteSelect',
			code: 'APPEAL_REASON',
			span: 12,
			disabled: true,
		},
		{
			label: '申诉单位所在详细地址',
			prop: 'orgAddress',
			type: 'text',
			span: 12,
			disabled: true,
		},
		{
			label: '申诉说明',
			prop: 'appealDescribe',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 24,
			disabled: true,
		},
		{
			label: '申诉处理结果',
			prop: 'handleStatus',
			propName: 'handleStatusLabel',
			type: 'radio',
			span: 24,
			dicData: [
				{
					label: '判定有效',
					value: 1,
					type: 'success',
				},
				{
					label: '判定异常',
					value: 4,
					type: 'danger',
				},
			],
		},
	],
}

export const api = {
	index: 'view_omReposOrder_appealPage',
	edit: 'view_omAppeal_add',
	approval: 'view_omAppeal_approval',
	detail: 'view_omAppeal_view',
}

export const auth = {
	...api,
	edit: 'self_omAppeal_more_approval',
	approval: 'self_omAppeal_approval',
}
export const baseConfig = {
	pageName: '异常数据管理',
	dictcodes: ['APPEAL_REASON', 'REPOS_COMPARE_RULE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'orderNo',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuAction: [
		{
			icon: 'editor',
			label: '批量申诉',
			type: 'primary',
			operate: 'multipleAppeal',
			auth: auth.edit,
			show: userInfo.authArea,
		},
	],
	menuBtn: [
		{
			icon: 'editor',
			label: '申诉处理',
			type: 'primary',
			operate: 'approval',
			auth: auth.approval,
			text: true,
			hideBtn: userInfo.classifyId != 3,
			condition: (row) => {
				return row.handleStatus == 0
			},
		},
		{
			icon: 'editor',
			label: '异常申诉',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
			condition: (row) => {
				return row.handleStatus == undefined || row.handleStatus == 3 ? true : false
			},
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			condition: (row) => {
				return row.appealId ? true : false
			},
			text: true,
			show: true,
		},
	],
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, 'org')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig,
}
